package com.example.wj.config;

import com.example.wj.interceptor.LoginInterceptor;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootConfiguration
public class MyWebConfig implements WebMvcConfigurer {
    @Bean
    /*
    * 得到拦截器
    * */
    public LoginInterceptor getLoginInterceptor(){
        return new LoginInterceptor();
    }
//    拦截器产生的路径
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getLoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/index.html").excludePathPatterns("api/logout");
        System.out.println("产生拦截");
    }
//    跨域路径
@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**")

            .allowedOrigins("*")
            .allowedMethods("*")
            .allowedHeaders("*");
}

}
